package com.example.administrator.foodrowfresh.fragmentframework;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.administrator.foodrowfresh.R;
import com.example.administrator.foodrowfresh.jiao.FindPassActivity;
import com.example.administrator.foodrowfresh.jiao.FreeRegistrationActivity;
import com.example.administrator.foodrowfresh.superBase.MyBaseFragment;


/**
 * Created by Administrator on 2016/4/30.
 */
public class ShoppingCart extends MyBaseFragment implements View.OnClickListener {
    //用户名，密码；
    private EditText userET, passET;
    private View mView;
    private Button mButton;
    private Button mFreebtn;
    private String userTell;
    private String pass;
    private String stringUser;
    private String stringPass;
    private SharedPreferences sharedPreferences;

    @Override
    public View initView() {
        mView = LayoutInflater.from(getActivity()).inflate(R.layout.layout_shopping_fm, null, false);
        mButton = (Button) mView.findViewById(R.id.shopping_bt_find_pass);
        mFreebtn = (Button) mView.findViewById(R.id.shopping_bt_free_register);


        userET = (EditText) mView.findViewById(R.id.shopping_pass_et);
        passET = (EditText) mView.findViewById(R.id.shopping_user_et);
        initData();
        return mView;
    }

    @Override
    public void initData() {
        mButton.setOnClickListener(this);
        mFreebtn.setOnClickListener(this);
    }

    public void onClick(View view) {

        if (view != null) {
            Intent intent = new Intent();
            switch (view.getId()) {
                case R.id.shopping_bt_login:
                    stringUser = userET.getText().toString();
                    stringPass = passET.getText().toString();
                    // 查询BD

                    //判断手机是否注册过
                    //判断两次密码输入是否一致
                    // 验证验证码
                    sharedPreferences = getActivity().getSharedPreferences("login", Context.MODE_PRIVATE);

                        //SharedPreferences读数据
                        // 读取已保存的数据
                        String content = sharedPreferences.getString("content", "default value");
                        String pass = sharedPreferences.getString("pass", "default value");
                        if (content.equals(stringUser)&& stringPass.equals(pass)){
                        Toast.makeText(getActivity(), "登录成功！", Toast.LENGTH_SHORT).show();

                        }
                    break;
                case R.id.shopping_bt_find_pass:
                    intent.setClass(getActivity(), FindPassActivity.class);
                    break;
                case R.id.shopping_bt_free_register:
                    intent.setClass(getActivity(), FreeRegistrationActivity.class);
                    break;
            }

            startActivity(intent);
        }
    }
}
